package mobileXversion1.diagram.navigator;

import org.eclipse.gmf.runtime.common.ui.services.parser.IParser;
import org.eclipse.gmf.runtime.common.ui.services.parser.ParserOptions;
import org.eclipse.gmf.runtime.emf.core.util.EObjectAdapter;
import org.eclipse.gmf.runtime.emf.type.core.IElementType;
import org.eclipse.gmf.runtime.notation.View;
import org.eclipse.jface.resource.ImageDescriptor;
import org.eclipse.jface.resource.ImageRegistry;
import org.eclipse.jface.viewers.ITreePathLabelProvider;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.TreePath;
import org.eclipse.jface.viewers.ViewerLabel;
import org.eclipse.swt.graphics.Image;
import org.eclipse.ui.IMemento;
import org.eclipse.ui.navigator.ICommonContentExtensionSite;
import org.eclipse.ui.navigator.ICommonLabelProvider;

/**
 * @generated
 */
public class MobileXversion1NavigatorLabelProvider extends LabelProvider
		implements ICommonLabelProvider, ITreePathLabelProvider {

	/**
	 * @generated
	 */
	static {
		mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put("Navigator?UnknownElement", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
		mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
				.getInstance()
				.getImageRegistry()
				.put("Navigator?ImageNotFound", ImageDescriptor.getMissingImageDescriptor()); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	public void updateLabel(ViewerLabel label, TreePath elementPath) {
		Object element = elementPath.getLastSegment();
		if (element instanceof mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem
				&& !isOwnView(((mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem) element)
						.getView())) {
			return;
		}
		label.setText(getText(element));
		label.setImage(getImage(element));
	}

	/**
	 * @generated
	 */
	public Image getImage(Object element) {
		if (element instanceof mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup) {
			mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup group = (mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup) element;
			return mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().getBundledImage(group.getIcon());
		}

		if (element instanceof mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem) {
			mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem navigatorItem = (mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return super.getImage(element);
			}
			return getImage(navigatorItem.getView());
		}

		return super.getImage(element);
	}

	/**
	 * @generated
	 */
	public Image getImage(View view) {
		switch (mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
				.getVisualID(view)) {
		case mobileXversion1.diagram.edit.parts.ContainerEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Diagram?http://MobileXversion1/1.0?Container", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Container_1000); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.AppMobileEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://MobileXversion1/1.0?AppMobile", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.AppMobile_2001); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ImageEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://MobileXversion1/1.0?Image", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Image_2002); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.InputEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://MobileXversion1/1.0?Input", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Input_2003); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.SettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://MobileXversion1/1.0?Setting", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Setting_2004); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ViewEditPart.VISUAL_ID:
			return getImage(
					"Navigator?TopLevelNode?http://MobileXversion1/1.0?View", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.View_2005); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.AppMobileMainViewEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?AppMobile?mainView", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.AppMobileMainView_4001); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ViewViewSettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?View?viewSetting", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.ViewViewSetting_4002); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ViewNextViewsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?View?nextViews", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.ViewNextViews_4003); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.AppMobileAppSettingEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?AppMobile?appSetting", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.AppMobileAppSetting_4004); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ComponentComponentEventsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?Component?componentEvents", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.ComponentComponentEvents_4005); //$NON-NLS-1$
		case mobileXversion1.diagram.edit.parts.ViewViewEventsEditPart.VISUAL_ID:
			return getImage(
					"Navigator?Link?http://MobileXversion1/1.0?View?viewEvents", mobileXversion1.diagram.providers.MobileXversion1ElementTypes.ViewViewEvents_4006); //$NON-NLS-1$
		}
		return getImage("Navigator?UnknownElement", null); //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private Image getImage(String key, IElementType elementType) {
		ImageRegistry imageRegistry = mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
				.getInstance().getImageRegistry();
		Image image = imageRegistry.get(key);
		if (image == null
				&& elementType != null
				&& mobileXversion1.diagram.providers.MobileXversion1ElementTypes
						.isKnownElementType(elementType)) {
			image = mobileXversion1.diagram.providers.MobileXversion1ElementTypes
					.getImage(elementType);
			imageRegistry.put(key, image);
		}

		if (image == null) {
			image = imageRegistry.get("Navigator?ImageNotFound"); //$NON-NLS-1$
			imageRegistry.put(key, image);
		}
		return image;
	}

	/**
	 * @generated
	 */
	public String getText(Object element) {
		if (element instanceof mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup) {
			mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup group = (mobileXversion1.diagram.navigator.MobileXversion1NavigatorGroup) element;
			return group.getGroupName();
		}

		if (element instanceof mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem) {
			mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem navigatorItem = (mobileXversion1.diagram.navigator.MobileXversion1NavigatorItem) element;
			if (!isOwnView(navigatorItem.getView())) {
				return null;
			}
			return getText(navigatorItem.getView());
		}

		return super.getText(element);
	}

	/**
	 * @generated
	 */
	public String getText(View view) {
		if (view.getElement() != null && view.getElement().eIsProxy()) {
			return getUnresolvedDomainElementProxyText(view);
		}
		switch (mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
				.getVisualID(view)) {
		case mobileXversion1.diagram.edit.parts.ContainerEditPart.VISUAL_ID:
			return getContainer_1000Text(view);
		case mobileXversion1.diagram.edit.parts.AppMobileEditPart.VISUAL_ID:
			return getAppMobile_2001Text(view);
		case mobileXversion1.diagram.edit.parts.ImageEditPart.VISUAL_ID:
			return getImage_2002Text(view);
		case mobileXversion1.diagram.edit.parts.InputEditPart.VISUAL_ID:
			return getInput_2003Text(view);
		case mobileXversion1.diagram.edit.parts.SettingEditPart.VISUAL_ID:
			return getSetting_2004Text(view);
		case mobileXversion1.diagram.edit.parts.ViewEditPart.VISUAL_ID:
			return getView_2005Text(view);
		case mobileXversion1.diagram.edit.parts.AppMobileMainViewEditPart.VISUAL_ID:
			return getAppMobileMainView_4001Text(view);
		case mobileXversion1.diagram.edit.parts.ViewViewSettingEditPart.VISUAL_ID:
			return getViewViewSetting_4002Text(view);
		case mobileXversion1.diagram.edit.parts.ViewNextViewsEditPart.VISUAL_ID:
			return getViewNextViews_4003Text(view);
		case mobileXversion1.diagram.edit.parts.AppMobileAppSettingEditPart.VISUAL_ID:
			return getAppMobileAppSetting_4004Text(view);
		case mobileXversion1.diagram.edit.parts.ComponentComponentEventsEditPart.VISUAL_ID:
			return getComponentComponentEvents_4005Text(view);
		case mobileXversion1.diagram.edit.parts.ViewViewEventsEditPart.VISUAL_ID:
			return getViewViewEvents_4006Text(view);
		}
		return getUnknownElementText(view);
	}

	/**
	 * @generated
	 */
	private String getContainer_1000Text(View view) {
		mobileXversion1.Container domainModelElement = (mobileXversion1.Container) view
				.getElement();
		if (domainModelElement != null) {
			return domainModelElement.getAppName();
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance()
					.logError(
							"No domain element for view with visualID = " + 1000); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getAppMobile_2001Text(View view) {
		IParser parser = mobileXversion1.diagram.providers.MobileXversion1ParserProvider
				.getParser(
						mobileXversion1.diagram.providers.MobileXversion1ElementTypes.AppMobile_2001,
						view.getElement() != null ? view.getElement() : view,
						mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
								.getType(mobileXversion1.diagram.edit.parts.AppMobileAppNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5001); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getImage_2002Text(View view) {
		IParser parser = mobileXversion1.diagram.providers.MobileXversion1ParserProvider
				.getParser(
						mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Image_2002,
						view.getElement() != null ? view.getElement() : view,
						mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
								.getType(mobileXversion1.diagram.edit.parts.ImageNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5002); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getInput_2003Text(View view) {
		IParser parser = mobileXversion1.diagram.providers.MobileXversion1ParserProvider
				.getParser(
						mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Input_2003,
						view.getElement() != null ? view.getElement() : view,
						mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
								.getType(mobileXversion1.diagram.edit.parts.InputNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5003); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getSetting_2004Text(View view) {
		IParser parser = mobileXversion1.diagram.providers.MobileXversion1ParserProvider
				.getParser(
						mobileXversion1.diagram.providers.MobileXversion1ElementTypes.Setting_2004,
						view.getElement() != null ? view.getElement() : view,
						mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
								.getType(mobileXversion1.diagram.edit.parts.SettingSettingNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5004); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getView_2005Text(View view) {
		IParser parser = mobileXversion1.diagram.providers.MobileXversion1ParserProvider
				.getParser(
						mobileXversion1.diagram.providers.MobileXversion1ElementTypes.View_2005,
						view.getElement() != null ? view.getElement() : view,
						mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
								.getType(mobileXversion1.diagram.edit.parts.ViewViewNameEditPart.VISUAL_ID));
		if (parser != null) {
			return parser.getPrintString(new EObjectAdapter(
					view.getElement() != null ? view.getElement() : view),
					ParserOptions.NONE.intValue());
		} else {
			mobileXversion1.diagram.part.MobileXversion1DiagramEditorPlugin
					.getInstance().logError(
							"Parser was not found for label " + 5005); //$NON-NLS-1$
			return ""; //$NON-NLS-1$
		}
	}

	/**
	 * @generated
	 */
	private String getAppMobileMainView_4001Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewViewSetting_4002Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewNextViews_4003Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getAppMobileAppSetting_4004Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getComponentComponentEvents_4005Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getViewViewEvents_4006Text(View view) {
		return ""; //$NON-NLS-1$
	}

	/**
	 * @generated
	 */
	private String getUnknownElementText(View view) {
		return "<UnknownElement Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	private String getUnresolvedDomainElementProxyText(View view) {
		return "<Unresolved domain element Visual_ID = " + view.getType() + ">"; //$NON-NLS-1$  //$NON-NLS-2$
	}

	/**
	 * @generated
	 */
	public void init(ICommonContentExtensionSite aConfig) {
	}

	/**
	 * @generated
	 */
	public void restoreState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public void saveState(IMemento aMemento) {
	}

	/**
	 * @generated
	 */
	public String getDescription(Object anElement) {
		return null;
	}

	/**
	 * @generated
	 */
	private boolean isOwnView(View view) {
		return mobileXversion1.diagram.edit.parts.ContainerEditPart.MODEL_ID
				.equals(mobileXversion1.diagram.part.MobileXversion1VisualIDRegistry
						.getModelID(view));
	}

}
